package com.yw.mq.example.m02_delay;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.MessageQueueSelector;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.common.message.MessageQueue;

import java.util.ArrayList;
import java.util.List;

import static com.yw.mq.core.MqConstant.DEFAULT_PRODUCER_GROUP;
import static com.yw.mq.core.MqConstant.NAME_SERVER_ADDR;

public class Producer {
    public static void main(String[] args) throws Exception {

        //  创建生产者
        DefaultMQProducer producer = new DefaultMQProducer(DEFAULT_PRODUCER_GROUP);
        // 设置连接信息
        producer.setNamesrvAddr(NAME_SERVER_ADDR);
        // 启动
        producer.start();

        Message message = new Message();
        message.setKeys(IdUtil.getSnowflakeNextIdStr());
        message.setTopic("order_topic");
        message.setTags("food");
        message.setDelayTimeSec(10L);
        message.setBody("hello mq".getBytes());

        SendResult sendResult = producer.send(message);

        System.out.println("当前时间：" + DateUtil.now() + ",发送延迟消息结果：" + sendResult);

        producer.shutdown();


    }
}
